﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using WarOfDev.Web.ViewModels;
using WarOfDev.EF;

namespace WarOfDev.Web.Models.MappingToViewModel
{
    public static class RoleMapping
    {
        public static void BaseToViewModel(RoleViewModel vm, Role model)
        {
            vm.Id = model.Id;
            vm.IsLocked = model.IsLocked;
            vm.ModifiedBy = model.ModifiedBy;
            vm.ModifiedOn = model.ModifiedOn;
            vm.CreatedBy = model.CreatedBy;
            vm.CreatedOn = model.CreatedOn;

            vm.Permissions = model.Permissions;
            vm.RoleName = model.RoleName;
            vm.Description = model.Description;
            vm.Groups = model.Groups;

            if (vm.Groups.Count() > 0)
            {
                var group = vm.Groups.First();
                vm.GroupId = group.GroupId;
                vm.GroupName = group.Group != null ? group.Group.GroupName : string.Empty;
            }

        }

        public static RoleViewModel ToViewModel(this Role model)
        {
            RoleViewModel vm = new RoleViewModel();
            BaseToViewModel(vm, model);

            return vm;
        }

    }
}